home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.7 KB | 411 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWExcDef.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWEXCDEF_H
- #define FWEXCDEF_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #include <setjmp.h>
-
- // The _FW_AUTO_PROTO macros are only expanded for Windows! %%% SFU %%%
-
- #ifdef FW_BUILD_WIN
- #define _FW_AUTO_PROTO1 extern void FW_PrivStaticDestroyer(className* self); /* KVV */
- #define _FW_AUTO_PROTO2 extern void FW_PrivStaticDestroyer(className< Type >* self);
- #define _FW_AUTO_PROTO3 extern void FW_PrivStaticDestroyer(className< Type1, Type2 >* self);
- #else
- #define _FW_AUTO_PROTO1
- #define _FW_AUTO_PROTO2
- #define _FW_AUTO_PROTO3
- #endif
-
- #ifdef FW_ANSI_TEMPLATE_INSTANTIATION
- // Unfortunately specializing a template function is compiler dependent.
- // Metrowerks wants all definitions to be present when it sees the instantiation, and
- // will give a compile error for definitions not yet seen, even if the occur later
- // in the translation unit.
- // Symantec does the opposite. If a specialized member function is given before
- // the template instantiation, it is (quietly) clobbered when the instantiation happens.
- // The result is missing definitions, unless the specializations come after the instantiation.
- #ifdef __MWERKS__
- #define _FW_INSTANTIATE_BEFORE1(className, Type)
- #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2)
- #define _FW_INSTANTIATE_AFTER1(className, Type) template class className<Type>;
- #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2) template class className<Type1, Type2>;
- #endif
- #ifdef __SC__
- #define _FW_INSTANTIATE_BEFORE1(className, Type) template class className<Type>;
- #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2) template class className<Type1, Type2>;
- #define _FW_INSTANTIATE_AFTER1(className, Type)
- #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2)
- #endif
- #else
- #define _FW_INSTANTIATE_BEFORE1(className, Type)
- #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2)
- #define _FW_INSTANTIATE_AFTER1(className, Type)
- #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2)
- #endif
-
- #ifdef FW_NATIVE_EXCEPTIONS
-
- // --------------- Native exceptions
-
- #define FW_TRY \
- try
-
- #define FW_CATCH_BEGIN
-
- #define FW_CATCH(class, error) \
- catch(class error)
-
- #define FW_CATCH_REFERENCE(class, error) \
- catch(class& error)
-
- #define FW_CATCH_NO_INSTANCE(class) \
- catch(class)
-
- #define FW_CATCH_EVERYTHING() \
- catch(...)
-
- #define FW_CATCH_END
-
- #define FW_THROW(error) throw error
- #define FW_THROW_SAME() throw
-
- #define FW_NEW(class, args) new class##args
-
- #define FW_VOLATILE(variable)
-
- #define FW_END_CONSTRUCTOR
- #define FW_START_DESTRUCTOR
- #define FW_DECLARE_AUTO(className)
- #define FW_DEFINE_AUTO(className)
- #define FW_DEFINE_AUTO_TEMPLATE(className, Type) template class className<Type>;
- #define FW_DEFINE_AUTO_TEMPLATE2(className, Type1, Type2) template class className<Type1, Type2>;
- #define FW_DECLARE_EXCEPTION(className) FW_DECLARE_CLASS
- #define FW_DEFINE_EXCEPTION(className)
-
- #else
-
- // --------------- Emulated exceptions
-
- #define FW_TRY \
- { \
- jmp_buf __jumpBuffer; \
- if(setjmp(__jumpBuffer) == 0) \
- { \
- FW_CPrivTryBlockContext __context(__jumpBuffer, longjmp);
-
- #define FW_CATCH_BEGIN \
- } \
- else \
- { \
- if (0) \
- {
-
- #define FW_CATCH(aClass, error) \
- } \
- else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
- { \
- aClass error = * (aClass*) FW_PrivGetThrownException(); \
- FW_PrivCaughtException(&error, sizeof(aClass), FW_PrivStaticGetClassInfo((aClass*)0), FW_PrivGetDestroyProc(&error), FW_PrivGetCloneProc(&error));
-
- #define FW_CATCH_REFERENCE(aClass, error) \
- } \
- else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
- { \
- aClass & error = *(aClass*) FW_PrivGetThrownException(); \
- FW_PrivCaughtReferenceException();
-
- #define FW_CATCH_NO_INSTANCE(aClass) \
- } \
- else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
- { \
- FW_PrivCaughtNoInstanceException();
-
- #define FW_CATCH_EVERYTHING() \
- } \
- else if (1) \
- { \
- FW_PrivCaughtEverythingException();
-
- #define FW_CATCH_END \
- } \
- else \
- { \
- FW_PrivKeepThrowing(); \
- } \
- FW_PrivCatchCleanup(); \
- } \
- }
-
- #define FW_THROW(error) \
- FW_PrivThrowException(error)
-
- #define FW_THROW_SAME() \
- FW_PrivThrowSame()
-
- #define FW_NEW(class, args) (class*) \
- ( \
- new(FW_CPrivWatcher(FW_PrivGetDeleteProc((const class*)0))) class##args, \
- FW_PrivWatcher_Pop() \
- )
-
- #define FW_VOLATILE(variable) FW_gPrivVolatileKludge = &variable
-
- //----------------------------------------------------------------------------------------
- // macro FW_DEFINE_AUTO
- //
- // This macro must be invoked in the .cpp file that contains all of the definitions of
- // the constructors of an auto-destruct class.
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_DEBUG
- #define _FW_DECLARE_AUTO_NAME(className) \
- friend char* FW_PrivGetAutoName(const className*);
- #define _FW_DEFINE_AUTO_NAME(className) \
- char* FW_PrivGetAutoName(const className*) \
- { \
- return #className; \
- }
- #define _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type) \
- char* FW_PrivGetAutoName(const className< Type >*) \
- { \
- return #className#Type; \
- }
- #define _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2) \
- char* FW_PrivGetAutoName(const className< Type1, Type2 >*) \
- { \
- return #className#Type1#Type2; \
- }
- #else
- #define _FW_DECLARE_AUTO_NAME(className)
- #define _FW_DEFINE_AUTO_NAME(className)
- #define _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type)
- #define _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2)
- #endif
-
- #define FW_DECLARE_AUTO(className) \
- _FW_DECLARE_AUTO_NAME(className) \
- friend FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*); \
- friend FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*); \
- void* operator new(size_t size, const FW_CPrivWatcher &w); \
- void operator delete(void* p); \
- private: \
- void* operator new(size_t); \
- public:
-
- #define FW_DEFINE_AUTO(className) \
- _FW_DEFINE_AUTO_NAME(className) \
- _FW_AUTO_PROTO1 \
- extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*); \
- extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*); \
- extern "C" \
- { \
- static void FW_PrivStaticDestroyer##className(void* self) \
- { \
- FW_PrivStaticDestroyer((className*) self); \
- } \
- static void FW_PrivStaticDeleter##className(void* p) \
- { \
- className::operator delete(p); \
- } \
- } \
- FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*) \
- { \
- return FW_PrivStaticDestroyer##className; \
- } \
- FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*) \
- { \
- return FW_PrivStaticDeleter##className; \
- } \
- void* className::operator new(size_t size, const FW_CPrivWatcher &w) \
- { \
- return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
- } \
- void className::operator delete(void* p) \
- { \
- FW_PrimitiveFreeBlock(p); \
- } \
- void* className::operator new(size_t) \
- { \
- FW_ASSERT(("Bad call to hidden operator new!", false)); \
- return 0; \
- } \
-
- #define FW_DEFINE_AUTO_TEMPLATE(className, Type) \
- extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type>*); \
- extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type>*); \
- _FW_INSTANTIATE_BEFORE1(className, Type) \
- void* className<Type>::operator new(size_t size, const FW_CPrivWatcher &w) \
- { \
- return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
- } \
- void className<Type>::operator delete(void* p) \
- { \
- FW_PrimitiveFreeBlock(p); \
- } \
- void* className<Type>::operator new(size_t) \
- { \
- FW_ASSERT(("Bad call to hidden operator new!", false)); \
- return 0; \
- } \
- _FW_INSTANTIATE_AFTER1(className, Type) \
- _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type) \
- _FW_AUTO_PROTO2 \
- extern "C" \
- { \
- static void FW_PrivStaticDestroyer##className##Type(void* self) \
- { \
- FW_PrivStaticDestroyer((className< Type >*) self); \
- } \
- static void FW_PrivStaticDeleter##className##Type(void* p) \
- { \
- className< Type >::operator delete(p); \
- } \
- } \
- FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type>*) \
- { \
- return FW_PrivStaticDestroyer##className##Type; \
- } \
- FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type>*) \
- { \
- return FW_PrivStaticDeleter##className##Type; \
- }
-
- #define FW_DEFINE_AUTO_TEMPLATE2(className, Type1, Type2) \
- _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2) \
- _FW_AUTO_PROTO3 \
- extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type1, Type2>*); \
- extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type1, Type2>*); \
- _FW_INSTANTIATE_BEFORE2(className, Type1, Type2) \
- void* className< Type1, Type2 >::operator new(size_t size, const FW_CPrivWatcher &w) \
- { \
- return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
- } \
- void className< Type1, Type2 >::operator delete(void* p) \
- { \
- FW_PrimitiveFreeBlock(p); \
- } \
- void* className< Type1, Type2 >::operator new(size_t) \
- { \
- FW_ASSERT(("Bad call to hidden operator new!", false)); \
- return 0; \
- } \
- _FW_INSTANTIATE_AFTER2(className, Type1, Type2) \
- extern "C" \
- { \
- static void FW_PrivStaticDestroyer##className##Type1##Type2(void* self) \
- { \
- FW_PrivStaticDestroyer((className< Type1, Type2 >*) self); \
- } \
- static void FW_PrivStaticDeleter##className##Type1##Type2(void* p) \
- { \
- className< Type1, Type2 >::operator delete(p); \
- } \
- } \
- FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type1, Type2>*) \
- { \
- return FW_PrivStaticDestroyer##className##Type1##Type2; \
- } \
- FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type1, Type2>*) \
- { \
- return FW_PrivStaticDeleter##className##Type1##Type2; \
- } \
-
- //----------------------------------------------------------------------------------------
- // macro FW_END_CONSTRUCTOR
- //
- // This macro must be invoked at the end of every constructor of an auto-destruct class
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_DEBUG
- #define FW_END_CONSTRUCTOR \
- FW_AutoConstructed(this, sizeof(*this), FW_PrivGetDestroyProc(this), FW_PrivGetAutoName(this));
- #else
- #define FW_END_CONSTRUCTOR \
- FW_AutoConstructed(this, sizeof(*this), FW_PrivGetDestroyProc(this));
- #endif
-
- //----------------------------------------------------------------------------------------
- // macro FW_START_DESTRUCTOR
- //
- // This macro must be invoked at the beginning of the destructor of an auto-destruct class
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_DEBUG
- #define FW_START_DESTRUCTOR \
- FW_AutoDestructed(this, FW_PrivGetDestroyProc(this), FW_PrivGetAutoName(this));
- #else
- #define FW_START_DESTRUCTOR \
- FW_AutoDestructed(this);
- #endif
-
- //----------------------------------------------------------------------------------------
- // macro FW_DEFINE_EXCEPTION
- //
- // This macro must be invoked in the .cpp file that contains all of the definitions of
- // the constructors of an exception class.
- //----------------------------------------------------------------------------------------
-
- #define FW_DECLARE_EXCEPTION(className) \
- FW_DECLARE_CLASS \
- friend FW_PrivCloneProc FW_PrivGetCloneProc(const className*); \
- friend FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*);
-
- #define FW_DEFINE_EXCEPTION(className) \
- _FW_AUTO_PROTO1 \
- extern "C" \
- { \
- static void FW_PrivStaticDestroyer##className(void* self) \
- { \
- FW_PrivStaticDestroyer((className*) self); \
- } \
- static void FW_PrivStaticCloner##className(void* self, void* destination, size_t destSize) \
- { \
- FW_PrivClone((className*) self, destination, destSize); \
- } \
- } \
- FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*) \
- { \
- return FW_PrivStaticDestroyer##className; \
- } \
- FW_PrivCloneProc FW_PrivGetCloneProc(const className*) \
- { \
- return FW_PrivStaticCloner##className; \
- }
-
-
- #endif
-
- #if 0
- #define FW_DECLARE_THROW_POINT(NAME) FW_CExceptionThrowPoint FW_g##NAME##ThrowPoint (#NAME)
- #define FW_CHECK_THROW_POINT(NAME) FW_g##NAME##ThrowPoint.Check ()
- #else
- #define FW_DECLARE_THROW_POINT(NAME)
- #define FW_CHECK_THROW_POINT(NAME)
- #endif
-
- #endif
-